import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { resolve } from "path"
// https://vitejs.dev/config/
export default defineConfig({
  server: { //主要是加上这段代码
    // host: '127.0.0.1',
    // port: 3000,
    proxy: {
      '/api': {
        target: "http://152.136.42.103:8080",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: [
      // 设置路径别名
      {
        find: "@",
        replacement: resolve(__dirname, "./src")
      }
    ]
  },
  css: {
    preprocessorOptions: {
      scss: {
        // additionalData: '@import "./src/assets/var-css/index.scss";'
      }
    }
  },
  build: {
    rollupOptions: {
      output: {
        chunkFileNames: 'js/[name]-[hash].js', // 引入文件名的名称
        entryFileNames: 'js/[name]-[hash].js', // 包的入口文件名称
        assetFileNames: '[ext]/[name]-[hash].[ext]', // 资源文件像 字体，图片等
      }
    },
    minify: 'terser', // 启用 terser 压缩  
    terserOptions: {
      compress: {
        pure_funcs: ['console.log'], // 只删除 console.log 
        //drop_console: true, // 删除所有 console
        drop_debugger: true, // 删除 debugger  
      }
    }

  }

})
